package agenda.conection;

import java.sql.*;

/**
 * Clase que permite conectar con la base de datos
 * 
 * @author Pablo
 *
 */
public class DbConnection {
	static String bd = "agenda";
	static String login = "root";
	static String password = "root";
	static String url = "jdbc:mysql://localhost/" + bd;

	Connection connection = null;

	public DbConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");

			connection = DriverManager.getConnection(url, login, password);

		} catch (SQLException e) {
			System.out.println(e);
		} catch (ClassNotFoundException e) {
			System.out.println(e);
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	public Connection getConnection() {
		return connection;
	}

	public void desconectar() throws SQLException {
		connection.close();
		connection = null;
	}
}
